<!--
 * @Author: 260156 260156@gree.com.cn
 * @Date: 2022-08-10 14:16:04
 * @LastEditors: 260156 260156@gree.com.cn
 * @LastEditTime: 2022-08-18 10:49:34
 * @FilePath: \gree-zst-web\src\views\manage\organization\organization.vue
 * @Description: 
 * 
 * Copyright (c) 2022 by 260156 260156@gree.com.cn, All Rights Reserved. 
-->
<template>
  <div>
    <org-header
      @handleSearch="handleSearch"
      @handleDownload="handleDownload"
    ></org-header>
    <org-main
      :tableData="tableData"
      :loading="loading"
      @handleSearch="handleSearch"
    ></org-main>
  </div>
</template>
<script lang="ts" setup>
import OrgHeader from "./components/OrgHeader.vue";
import OrgMain from "./components/OrgMain.vue";
import { useManageStore } from "store/modules/manage";
import { downloadOrganization } from "api/manage/manage";
import type { TableData } from "./types";

const loading = ref<boolean>(false);

const manageStore = useManageStore();

const tableData = computed<TableData>(() => manageStore.organizationTree);

const handleSearch = () => {
  loading.value = true;
  manageStore.getOrganizationList().finally(() => (loading.value = false));
};
if (manageStore.organizationTree.length === 0) {
  handleSearch();
}

const handleDownload = () => {
  downloadOrganization({ fileName: "组织架构管理" });
};
</script>
